<?php
require('includes/top.php');


$acc_id = $_POST['acc_id'];
$depot_location = $_POST['depot_location'];
$quantity = $_POST['quantity'];
$date = date("d-m-y");
$sql = mysql_query("select * from accessories_stock where accessories_id=".$acc_id);
if(mysql_num_rows($sql) >0){
	while($row= mysql_fetch_array($sql))
	{	
	$total_quantity=$row["quantity"] + $quantity;
	$sql1="UPDATE accessories_stock SET `quantity` = '".$total_quantity."' where accessories_id='".trim($acc_id)."' and depot_location='".trim($depot_location)."'";
	$result1=mysql_query($sql1);
	}
}

else
 {
	$sql1="INSERT INTO accessories_stock(`accessories_id`,`quantity`,`depot_location`) VALUES ('$acc_id','$quantity','$depot_location')";
	$result1=mysql_query($sql1);
}

$sql2="INSERT INTO accessories_stock_details(`accessories_id`,`depot_location`,`quantity`,`date`) VALUES ('$acc_id','$depot_location','$quantity','$date')";
$result2=mysql_query($sql2);

if($result1>0)
{
header('Location: add_accessories_stock.php?v=success');
}
else
{
header('Location: add_accessories_stock.php?v=err');
}
?>